package com.ts.api.module.channel.entity.vo;

import com.gitee.apanlh.util.reflection.ClassConvertUtils;
import com.gitee.apanlh.util.reflection.ReflectionUtils;
import com.gitee.apanlh.util.valid.ValidParam;
import com.ts.api.module.channel.entity.po.ChannelFlowConfigPO;
import lombok.Data;

import java.lang.reflect.Field;

/**
 * 渠道流程配置VO
 */
@Data
public class RespChannelFlowConfigVO {

    /** 是否开启动画 */
    private boolean enableMovie;
    /** 是否开启贷超页匹配弹窗 */
    private boolean enableMarketMatchPopUp;
    /** 是否开启贷超列表(0关闭 1开启)默认关闭 */
    private boolean enableMarketList;
    /** 是否开启表单 */
    private boolean enableForm;
    /** 是否开启短信 */
    private boolean enableSms;
    /** 开启二次授权 */
    private boolean enableSecondAccept;
    /** 是否开启分发流程(0关闭 1开启) */
    private boolean enableMatchFlow;
    /** 是否开启分发流程(0关闭 1开启) */
    private boolean enableNoneOrgLinkToMarket;
    /** 是否开启贷超额度领取完成页 */
    private boolean enableMarketFinish;
    /** 是否开启-注册登录后跳转贷超页(默认0关闭 1开启) */
    private boolean enableLoginMarketRedirect;
    /** 是否开启-注册登录后跳转贷超页(默认0关闭 1开启) */
    private boolean enableIpCityToForm;
    /** 退出拦截 */
    private boolean handlerQuit;
    /** 返回拦截 */
    private boolean handlerBack;

    public RespChannelFlowConfigVO() {
        super();
    }

    public RespChannelFlowConfigVO(ChannelFlowConfigPO channelFlowConfigPO) {
        Field[] fields = ReflectionUtils.getFields(this);

        for (Field field : fields) {
            //  获取配置类值
            Field channelFlowConfigPOField = ReflectionUtils.getField(channelFlowConfigPO, field.getName());
            Object fieldValue = ReflectionUtils.getFieldValue(channelFlowConfigPOField, channelFlowConfigPO);

            //  自动转换值VO类
            if (ValidParam.isNotNull(fieldValue)) {
                Integer fieldValueInt = (Integer) fieldValue;
                ReflectionUtils.setFieldValue(field, this, ClassConvertUtils.toBoolean(fieldValueInt));
            }
        }
    }

    /**
     *  转换配置实体类
     *
     *  @param  channelFlowConfigPO
     *  @return RespChannelFlowConfigVO
     */
    public static RespChannelFlowConfigVO convertVO(ChannelFlowConfigPO channelFlowConfigPO) {
        return new RespChannelFlowConfigVO(channelFlowConfigPO);
    }
}
